package com.suncaper.wcss.common.utls;

import com.suncaper.wcss.model.domain.User;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;

public class ExcelUtils {

    public static void exportUser(List<User> users, HttpServletResponse response) throws IOException {
        //创建工作薄对象
        HSSFWorkbook workbook=new HSSFWorkbook();//这里也可以设置sheet的Name
        //创建工作表对象
        HSSFSheet sheet = workbook.createSheet();
        HSSFRow row = sheet.createRow(0);
        row.createCell(0).setCellValue("学号");
        row.createCell(1).setCellValue("姓名");
        row.createCell(2).setCellValue("角色");
        for(int i=0;i<users.size();i++){
            row = sheet.createRow(i+1);//设置第一行，从零开始
           row.createCell(0).setCellValue(users.get(i).getSn());
           row.createCell(1).setCellValue(users.get(i).getName());
           row.createCell(2).setCellValue(users.get(i).getRoleId());
        }
        workbook.setSheetName(0,"用户信息");//设置sheet的Name
        workbook.write(response.getOutputStream());
    }
}
